﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace eVoting
{
    public partial class CreateCandidate : System.Web.UI.Page
    {
        DBManager db;
        protected void Page_Load(object sender, EventArgs e)
        {
            db = new DBManager();
            System.Collections.Generic.List <Poll> Polls = db.getAllPolls();

            PollDD.Items.Add("--");
             for (int i = 0; i < Polls.Count; i++)
            {
                PollDD.Items.Add(Polls[i].ID+","+Polls[i].name);
            }
        }

        protected void AddBtn_Click(object sender, EventArgs e)
        {
            if (FirstNameTB.Text != "" && MiddleNameTB.Text != "" && LastNameTB.Text != "" && PollDD.SelectedValue != "--")
            {
                String[] PollInfo = PollDD.SelectedValue.Split(',');
                if(db.createNewCandidate(FirstNameTB.Text, MiddleNameTB.Text, LastNameTB.Text, int.Parse(PollInfo[0]))!=null)
                {
                    ErrorLbl.Visible = true;
                    ErrorLbl.Text = "Added";
                }
                else
                {
                    ErrorLbl.Visible = true;
                }
            }
            else
            {
                ErrorLbl.Visible = true;
            }
        }
    }
}
